class User < ActiveRecord::Base
  validates_uniqueness_of :username
  validates_confirmation_of :password, :on => :create
  validates_length_of :password, :within => 6..12

  def self.authenticate(user_info)
      find_by_username_and_password(user_info[:username], user_info[:password])
    end

  def self.update_password(pass)
    self.password = pass
    self.save
  end
  
  def self.update_bio(newbio)
    self.bio = newbio
    self.save
  end
  
  def self.update_interests(inter)
    self.interests = inter
    self.save
  end
  
  def self.update_attributes(pass, inter, newbio)
    self.update_password(pass)
    self.update_interests(inter)
    self.update_bio(newbio)
  end

  def self.search(search)
    search = "%" + search + "%"
    find(:all, :conditions => ['username LIKE ?', search])
  end

end
